package com.example.moviegroup.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;

import com.example.moviegroup.R;

import java.util.Random;

/**
 * Created by walymin-love on 2015/11/19.
 */
public class ChouJiangActivity extends Activity implements View.OnClickListener {
    private ImageView iv_start;
    private ImageView iv_zhuanpan;
    private ImageView iv_choujiang_back;
    private Button btn_look;
    private Animation anim;
    Random ran;
    long time;
    boolean flag = true;
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            iv_zhuanpan.clearAnimation();
            //anim.setFillAfter(true);
            flag = true;
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choujiang);
        initView();
        setListener();
        initData();
    }

    public void initView() {
        iv_choujiang_back = (ImageView) findViewById(R.id.iv_zhuanpan_back);
        iv_start = (ImageView) findViewById(R.id.iv_start);
        iv_zhuanpan = (ImageView) findViewById(R.id.iv_zhuanpan);
        btn_look = (Button) findViewById(R.id.btn_look);
        anim = AnimationUtils.loadAnimation(this,R.anim.choujiang);
        ran = new Random();
        time = ran.nextInt(2000)+3000;

    }

    public void setListener() {
        iv_choujiang_back.setOnClickListener(this);
        iv_start.setOnClickListener(this);
        btn_look.setOnClickListener(this);
    }

    public void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_zhuanpan_back:
                finish();
                break;
            case R.id.iv_start:
                if(flag){
                    LinearInterpolator lin = new LinearInterpolator();
                    anim.setInterpolator(lin);
                    iv_zhuanpan.startAnimation(anim);
                    handler.sendEmptyMessageDelayed(1, time);
                    flag = false;
                }

                break;
            case R.id.btn_look:
                Intent intent = new Intent(ChouJiangActivity.this,XiangQingActivity.class);
                startActivity(intent);
                break;
        }
    }
}
